import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:osc/res/colors.dart';
import 'package:osc/res/dimens.dart';
import 'package:osc/res/strings.dart';
import 'package:osc/ui/widgets/small_widgets.dart';
import 'package:osc/utils/string_util.dart';

/*class LoadingDialog extends AlertDialog {
  String msg = StringIds.loading;
  LoadingDialog({String msg}){
    if(!StringUtil.isEmpty(msg)){
      this.msg = msg;
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        onWillPop: onWillPop,
        child: Center(
          child: new Container(
            padding: EdgeInsets.all(Dimens.gap_activity_horizontal),
            color: Colors.white,
            alignment: Alignment.center,
            height: 140,
            width: 140,
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  CircularProgressIndicator(
                    valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
                    backgroundColor: Colours.gray_66,
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: Dimens.gap_activity_vertical,),
                    child: SmallWidgets.buildText(msg, Colours.gray_33, Dimens.font_sp14),
                  )
                ],
              ),
            ),
          ),
        ),
    );
  }

  Future<bool> onWillPop() => new Future.value(false);
}*/


class LoadingDialog extends StatefulWidget {
  final String msg;
  final Function dismissDialogEvent;
  const LoadingDialog({Key key, @required this.dismissDialogEvent, this.msg}) : super(key: key);

  @override
  _LoadingDialogState createState() => new _LoadingDialogState(msg);
}

class _LoadingDialogState extends State<LoadingDialog> {
  String msg;
  _LoadingDialogState(this.msg);

  @override
  void initState() {
    super.initState();
    if(StringUtil.isEmpty(msg)){
      msg = StringIds.loading;
    }
    if(widget.dismissDialogEvent != null){
      widget.dismissDialogEvent(
          (){
            Navigator.of(context).pop();
          }
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: onWillPop,
      child: Center(
        child: new Container(
          padding: EdgeInsets.all(Dimens.gap_activity_horizontal),
          color: Colors.white,
          alignment: Alignment.center,
          height: 140,
          width: 140,
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
                  backgroundColor: Colours.gray_66,
                ),
                Padding(
                  padding: EdgeInsets.only(top: Dimens.gap_activity_vertical,),
                  child: SmallWidgets.buildText(msg, Colours.gray_33, Dimens.font_sp14),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  Future<bool> onWillPop() => new Future.value(false);
}

